<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.40/vue.global.js"></script>
</head>
<body>

    <div id="app">
        <button @click=" name = 'ihome' ">ihome</button>
        <button @click=" name = 'iwork' ">work</button>
        <button @click=" name = 'ifack' ">fack</button>
        <!-- keep-alive 会缓存包裹在其中的动态组件 如果不用其包裹，会直接卸载 -->
        <keep-alive>
            <component :is="name"></component>
        </keep-alive>
    </div>


    <template id="work">
        <div>
            work...
        </div>
        <input type="text">
    </template>
    <template id="fack">
        <div>
            fack...
        </div>
        <input type="text">
    </template>
</body>
</html>
<script>
    const ihome = {
        template:`<div>home...</div><input type="text">`
    }
    const app = Vue.createApp({
        data() {
            return {
                name:'ihome'
            }
        },
        components:{
            ihome,
            iwork:{
                template:'#work'
            },
            ifack:{
                template:'#fack'
            }
        }
    })
    app.mount('#app')
</script>